<?php
//模型：友情连接
//model/class.link.php
//by QINIAO

class qiLink{
	
	var $db;
	
  function qiLink($dbhandle)
	{
		$this->db = $dbhandle;
	}

//获取全部链接
	
	function getLinks()
	{
		$res = $this->db->query("SELECT * FROM ".DB_PREFIX."links ORDER BY id DESC");
		$links=array();
		while($row=mysql_fetch_array($res))
		{
			$row['name'] = $row['name'];
			$row['url'] = $row['url'];
			$links[]=$row;
		}
		return $links;
	}

//获取首页链接
	function getHomeLink()
	{
	$sql = "select * from ".DB_PREFIX."links where inhome='1' order by id desc";
	$res = $this->db->query($sql);
	$links = array();
	while($row = $this->db->fetch_array($res))
	{
	$links[] = $row;
	}
	return $links;
	}
	
//更新链接
	function updateLink($linkDate, $linkId)
	{
	$Item = array();
	foreach($linkDate as $key => $date)
	{
		$Item[] = "$key='$date'";
	}
	$upStr = implode(',',$Item);
	$this->db->query("UPDATE ".DB_PREFIX."links  SET  $upStr WHERE  id=$linkId");
	}
//添加链接
	function addLink($name,$url,$inhome)
	{
		$sql="INSERT INTO ".DB_PREFIX."links (name,url,inhome) VALUES ('$name','$url','$inhome')";
		$this->db->query($sql);
	}
//取得指定链接
	function getOneLink($linkId)
	{
		$sql = "select * from ".DB_PREFIX."links where id=$linkId";
		$res = $this->db->query($sql);
		$row = $this->db->fetch_array($res);
		$linkDate = array();
		if($row)
		{
			$linkDate = array(
				'sitename' => htmlspecialchars(trim($row['name'])),
				'siteurl'  => htmlspecialchars(trim($row['url'])),
				'siteinhome' => htmlspecialchars(trim($row['inhome']))
			);
		}
		return $linkDate;
	}
	
//删除链接
	function deleteLink($linkId)
	{
		$this->db->query("DELETE FROM ".DB_PREFIX."links where id=$linkId"); 
	}
	
	}

?>